


import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gczn_hd/app/core/base/handle_mixin.dart';
import 'package:gczn_hd/app/core/values/App_img.dart';
import 'package:gczn_hd/app/core/values/app_colors.dart';
import 'package:gczn_hd/app/core/values/app_values.dart';
import 'package:gczn_hd/app/core/values/text_styles.dart';
import 'package:gczn_hd/app/core/widget/custom_title_bar.dart';
import 'package:gczn_hd/app/core/widget/gczn_radio.dart';
import 'package:gczn_hd/app/modules/qms/check_detail/controllers/check_detail_controller.dart';
import 'package:get/get.dart';

class CheckOrderDetail extends StatelessWidget with HandleMixin{


  final CheckDetailController controller = Get.put(CheckDetailController());


@override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        CustomTitleBar(title: "检验明细", handleBtn: Text("根据风扇检验标准", style: textStyle20Opa8,),),
        Expanded(
          flex: 1,
          child: SingleChildScrollView(
            child: Column(
              children: [
                _buildItem(context),
                 SizedBox(height: AppValues.size30.h,),
                _buildUpload(),
                SizedBox(height: AppValues.size30.h,),
                _buildRemark()
              ],
            ),
          ),
        )
      ],
    );
  }


  Widget _buildRemark(){
    return Container(
      padding:  EdgeInsets.symmetric(horizontal: AppValues.size20.w),
      alignment: Alignment.topLeft,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: [
          Text("备注", style: textStyle,),
          SizedBox(height: AppValues.size20.h,),
          SizedBox(
            child: TextField(
              controller: controller.remarknputController,
              maxLines: 3,
                decoration: InputDecoration(
                  border: const OutlineInputBorder(
                      borderSide: BorderSide.none,
                      borderRadius: BorderRadius.zero
                  ),
                  focusedBorder: const OutlineInputBorder(
                    borderSide: BorderSide.none,
                  ),
                  filled: true,
                  fillColor: AppColors.gcznPrimaryColor,
                  hintText: '请输入',
                  hintStyle: textStyle,
                  contentPadding: EdgeInsets.symmetric(horizontal: AppValues.size20.w, vertical: AppValues.size20.h),
                )
            ),
          )
        ],
      ),
    );
  }

  /// 上传
  Widget _buildUpload(){

    return Container(
      padding:EdgeInsets.symmetric(horizontal: AppValues.size20.w),
      alignment: Alignment.topLeft,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: [
          Text("品质图片", style: textStyle,),
          SizedBox(height: AppValues.size20.h,),
          Wrap(
            spacing: AppValues.margin_10.w, // 水平间距
            runSpacing: AppValues.margin_10.h, // 垂直间距
            children: [
              _buildImageButton(),
              ..._buildImageList(),
            ],
          )
        ],
      ),
    );

  }

  /// 上传图片列表
  List<Widget> _buildImageList(){
    List<Widget> list = [];
    list = [1,2,3,4].map((item) => Stack(
      clipBehavior: Clip.none, // 禁用裁剪
      children: [
        Container(
          width: AppValues.size100.w,
          height: AppValues.size100.w,
          decoration: BoxDecoration(
            color: AppColors.counterBtn,
            borderRadius: BorderRadius.circular(AppValues.margin_12.r),
          ),
          child: Center(
            child: Image.asset(AppImg.defaultpic, fit: BoxFit.fill,),
          ),
        ),
        const Positioned(
          top: -5,
          right: -5,
          child: Icon(Icons.remove_circle_rounded, color: AppColors.dangerTextColor, size: 20,),
        )
      ],
    )).toList();
    

    return list;
  }

/// 上传按钮
  Widget _buildImageButton(){
    const Size iconSize = Size(31, 28);

    return  Container(
      width: AppValues.size100.w,
      height: AppValues.size100.w,
      decoration: BoxDecoration(
        color: AppColors.counterBtn,
        borderRadius: BorderRadius.circular(AppValues.margin_12.r),
      ),
      child:  Center( // 使用 Center 确保图像居中
        child: Image.asset( AppImg.uploadCamera, width: iconSize.width.w, height: iconSize.height.h, color: AppColors.colorWhite, colorBlendMode: BlendMode.srcIn, ),
      ),
    );
  }


Widget _buildItem(BuildContext context){
List<int> list = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
    List<Widget> widgets = [];

    for( int i = 0; i < list.length; i++ ){
      widgets.add(Container(
        width: double.infinity,
        padding: EdgeInsets.only(top: AppValues.size26.h, bottom: AppValues.size26.h),
        decoration: BoxDecoration(
          border: Border(bottom: BorderSide(color: const Color.fromRGBO(39, 65, 80, 1), width: 1.w))
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
              _buildCheckItem(),
              Expanded(
                flex: 1,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text("不良品项" , style: textStyle,),
                    SizedBox(height: AppValues.size20.h,),
                    Wrap(
                      spacing: AppValues.margin_10.w, // 水平间距
                      runSpacing: AppValues.margin_10.h, // 垂直间距
                      children: [
                        _buildBadItem(text: "未收紧 1.0"),
                        _buildBadItem(text: "未收紧 1.0"),
                        _buildBadButton(context)
                      ],
                    )
                  ],
                ),
              )
          ],
        ),
      ));
    }

    return Column(
      children: widgets,
    );

}


Widget _buildCheckItem(){

return Expanded(
    flex: 1,
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text("色差检查" , style: textStyle, maxLines: 1, overflow: TextOverflow.ellipsis,),
        SizedBox(height: AppValues.size14.h,),
        Text("检验是否有色差情况", style: textStyle20Opa.copyWith(fontSize: AppValues.size24.sp),),
        Row(
          children: [
             Text("检查结果: ", style: textStyle,),
            Obx(() => Expanded(
          flex: 1,
          child: Wrap(
            spacing: AppValues.size12,
            runSpacing: AppValues.size12,
            children: controller.seleces.map((item) => GcznRadio(value: item, label: item, onChanged: (String val){
              controller.selectLine.value = val;
            }, groupValue: controller.selectLine.value,)).toList(),
            ),
          ))
          ],
        )
      ],
      ),
  );

}

Widget _buildBadButton(BuildContext context){
  return GestureDetector(
    behavior: HitTestBehavior.opaque,
    onTap: (){
      showToast('openDrawer');
      Scaffold.of(context).openEndDrawer();
    },
    child: Container(
      width: AppValues.size60.w,
      height: AppValues.size60.w,
      padding: EdgeInsets.zero,
      decoration: BoxDecoration(
        color: AppColors.counterBtn,
        borderRadius: BorderRadius.circular(AppValues.margin_12.r),
      ),
      child: const Center(
        child: Text("+", style: TextStyle(color: AppColors.colorWhite),),
      ),
    ),
  );
}

 Widget _buildBadItem({required text}){

    return  Container(

      padding: EdgeInsets.only(left: AppValues.size28.w, right: AppValues.size28.w, top: AppValues.size12.w, bottom: AppValues.size12.w),
      decoration: BoxDecoration(
        color:AppColors.badBg,
        borderRadius: BorderRadius.circular(AppValues.margin_12.r),
      ),
      child: Text(text, style: textStyle,),
    );
  }



}